const TransformPages = require("uni-read-pages");
const {
	webpack
} = new TransformPages();
const path = require('path')
const resolve = dir => path.join(__dirname, dir)
const PORT = process.env.port || process.env.npm_config_port || 9528; // dev port
const API_URL = "http://122.112.207.45:9999";

module.exports = {
	transpileDependencies: ['uview-ui'],
	chainWebpack: config => {
		config.resolve.alias
			.set('@', resolve('src'))
	},

	// 配置转发代理
	devServer: {
		port: PORT,
		open: true,
		proxy: {
			"/api": {
				target: API_URL,
				// ws: false, // 需要websocket 开启
				changeOrigin: true,
				pathRewrite: {
					"^/api": "",
				},
			},
		},
	},
	configureWebpack: {
		module: {

			rules: [

				{

					test: /\.m?js$/,

					exclude: {

						and: [/node_modules/],

						not: [/@arcgis[\\/]core/]

					},

					use: {

						loader: "babel-loader",

						options: {

							plugins: [

								["@babel/plugin-proposal-nullish-coalescing-operator", { loose: true }],

								["@babel/plugin-proposal-optional-chaining", { loose: true }]

							]

						}

					}

				},
				{
					test: /\.md$/,
					use: [
						'html-loader',
						'markdown-loader'
					]
				},
				{
					test: /\.js$/,
					exclude: /node_modules/,
					use: 'babel-loader'
				},
				{
					test: /\.license$/,
					exclude: /node_modules/,
					loader: 'ignore-loader' // 或者使用其他适当的加载器进行忽略处理
				}

			]

		},
		plugins: [
			new webpack.DefinePlugin({
				ROUTES: webpack.DefinePlugin.runtimeValue(() => {
					const tfPages = new TransformPages({
						includes: ["path", "name", "meta", "aliasPath"],
					});
					return JSON.stringify(tfPages.routes);
				}, true),
			}),
		],

	},
};